package org.kazuhiko.rpg.server.net.packet;

import java.util.LinkedList;
import java.util.List;

public class PacketManager
{
	private List<PacketDefinition> incoming = new LinkedList<PacketDefinition>();
	private List<PacketDefinition> outgoing = new LinkedList<PacketDefinition>();
	
	private transient PacketDefinition[] incomingArray;
	private transient PacketDefinition[] outgoingArray;
	
	private Object readResolve()
	{
		incomingArray = new PacketDefinition[256];
		
		for( PacketDefinition def : incoming )
		{
			incomingArray[def.getId()] = def;
		}
		
		outgoingArray = new PacketDefinition[256];
		
		for( PacketDefinition def : outgoing )
		{
			outgoingArray[def.getId()] = def;
		}
		
		return this;
	}
	
	public PacketDefinition getIncomingPacket( int id )
	{
		return incomingArray[id];
	}
	
	public PacketDefinition getOutgoingPacket( int id )
	{
		return outgoingArray[id];
	}
}
